{include file="public/layout" /}

<body style="background-color: #FFF; overflow: auto;min-width:auto;">

<div class="users-modal-body">
    <div class="content">
        <div class="finance-module">
            <form id="postForm" autocomplete="off" class="users-form users-form-label-right">
                <div class="users-form-line users-form-line-required">
                    <label class="users-form-line-label">分享标题：</label>
                    <div class="users-form-line-content">
                        <div class="users-input-wrapper users-input-group">
                            <button type="button" class="" onclick="setLabel(this);" data-val="{ey_webname}" style="padding: 3px 5px;background: #3398cc;color: #fff;border: 1px solid #3398cc;border-radius: 2px;cursor: pointer;">变量标签</button>
                            <!--<input autocomplete="off" type="text" name="" id="" placeholder="变量标签" value="变量标签" class="users-input">-->
                        </div>
                    </div>
                </div>
                <div class="users-form-line users-form-line-required">
                    <label class="users-form-line-label">分享描述：</label>
                    <div class="users-form-line-content">
                        <div class="users-input-wrapper users-input-type-textarea">
                            <input type="text" autocomplete="off" name="web[web_share_title_wx]" id="web_share_title_wx" class="users-input" value="{$global.web_share_title_wx}">
                            <!--<textarea wrap="soft" autocomplete="off" spellcheck="false" name="remark" placeholder="请输入分享描述" rows="3" class="users-input"></textarea>-->
                        </div>
                    </div>
                </div>
                <!-- 分享图片商品详情分享时隐藏 -->
                <div class="users-form-line users-form-line-required">
                    <label class="users-form-line-label">分享图片：</label>
                    <div class="users-form-line-content">
                        <div class="users-input-wrapper users-input-group">
                            <div class="tab-pane pics" id="tab_proimg">
                                <table class="table table-bordered">
                                    <tbody>
                                        <tr>
                                            <td>
                                                <div class="sort-list">
                                                    <div class="images_upload" id="web_share_litpic_wx_div" style="width: 100px;{empty name='$global.web_share_litpic_wx'}display: none;{else /}display: block;{/empty}">
                                                        <div class="ic">
                                                            <div class="upimg">
                                                                <div class="icaction" style="display: none;">
                                                                    <span class="load_images" id="web_share_litpic_wx_update" onclick="GetUploadify(1, '', 'allimg', 'web_share_litpic_wx_callback');"><i class="iconfont e-bianji2 f-20"></i></span>
                                                                </div>
                                                                <div class="cover-bg" style="display: none;"></div>
                                                                <img id="web_share_litpic_wx_img" src="{$global.web_share_litpic_wx|default=''}">
                                                                <input type="hidden" name="web[web_share_litpic_wx]" id="web_share_litpic_wx" value="{$global.web_share_litpic_wx|default=''}">
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                                <a href="javascript:void(0);" onclick="GetUploadify(1, '', 'allimg', 'web_share_litpic_wx_callback');" class="img-upload mb15" title="点击上传" id="web_share_litpic_wx_a" {notempty name="$global.web_share_litpic_wx"}style="display: none;"{/notempty}>
                                                <div class="y-line"></div> <div class="x-line"></div>
                                                </a>
                                            </td>
                                        </tr>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<div class="users-modal-footer">
    <div>
        <button type="button" class="default-long users-btn" onclick="cancel();">
            <span>取消</span>
        </button>
        <button type="button" class="primary-long users-btn" onclick="confirm();">
            <span>确定</span>
        </button>
    </div>
</div>
<script>
    // 鼠标事件，加载查看大图和更新图片
    $(document).ready(function() {
        $("#web_share_title_wx").focus();
        $("#web_share_litpic_wx_div .upimg").live('mouseover', function() {
            $(this).find('div.icaction').show();
            $(this).find('div.cover-bg').show();
        }).live('mouseout', function() {
            $(this).find('div.icaction').hide();
            $(this).find('div.cover-bg').hide();
        });
    });

    // 商品主图回调加载
    function web_share_litpic_wx_callback(paths) {
        $('#web_share_litpic_wx_a').hide();
        $('#web_share_litpic_wx_div').show();
        $('#web_share_litpic_wx_div #web_share_litpic_wx').val(paths);
        $('#web_share_litpic_wx_div #web_share_litpic_wx_img').attr('src', paths);
        $('#web_share_litpic_wx_div #web_share_litpic_wx_update').attr('onclick', "GetUploadify(1, '', 'allimg', 'web_share_litpic_wx_callback');");
    }
    //点击在输入框光标位置插入内容
    function setLabel(obj) {
        var val = $(obj).attr('data-val');
        $('#web_share_title_wx').eyouInsertAtFocus(val);
    }
    (function($){
        $.fn.extend({
            eyouInsertAtFocus: function(myValue){
                var $t=$(this)[0];
                if (document.selection) {
                    this.focus();
                    sel = document.selection.createRange();
                    sel.text = myValue;
                    this.focus();
                }else if ($t.selectionStart || $t.selectionStart == '0') {
                    var startPos = $t.selectionStart;
                    var endPos = $t.selectionEnd;
                    var scrollTop = $t.scrollTop;
                    $t.value = $t.value.substring(0, startPos) + myValue + $t.value.substring(endPos, $t.value.length);
                    this.focus();
                    $t.selectionStart = startPos + myValue.length;
                    $t.selectionEnd = startPos + myValue.length;
                    $t.scrollTop = scrollTop;
                }else {
                    this.value += myValue;
                    this.focus();
                }
            }
        })
    })(jQuery);


    var parentObj = parent.layer.getFrameIndex(window.name);

    $(function () {
        var h = $('html').height();
        parent.layer.style(parentObj, {
            height: h+'px'
        });
    })
    function cancel() {
        parent.layer.closeAll();
    }
    function confirm() {

        if('' == $('#web_share_title_wx').val()){
            showErrorMsg('分享描述不能为空！');
            $('#web_share_title_wx').focus();
            return false;
        }
        if('' == $('#litpic').val()){
            showErrorMsg('分享图片不能为空！');
            return false;
        }

        layer_loading('正在处理');
        $.ajax({
            url : "{:url('Store/wechat_conf_share')}",
            data: $('#postForm').serialize(),
            type: 'post',
            dataType: 'json',
            success: function(res) {
                layer.closeAll();
                if (res.code == 1) {
                    var _parent = parent;
                    _parent.layer.close(parentObj);
                    _parent.layer.msg(res.msg, {shade: 0.3, time: 1000}, function(){
                        _parent.location.reload();
                    });
                } else {
                    layer.alert(res.msg, {icon: 2, title: false, closeBtn: 0});
                }
            },
            error: function(e) {
                layer.closeAll();
                showErrorMsg(e.responseText);
            }
        })
    }
</script>
